function processModuleExport(moduleExport) {
    return moduleExport && moduleExport.__esModule ? moduleExport : {
        default: moduleExport
    };
}

function defineProperty(obj, propertyName, value) {
    return propertyName in obj ? Object.defineProperty(obj, propertyName, {
        value: value,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : obj[propertyName] = value, obj;
}

function logMessage(message) {
    console.log(message);
}

function handleImageTap(event) {
    console.log(event);
    var from = event.target.dataset.from, index = event.target.dataset.idx;
    void 0 !== from && 0 < from.length && processImageTap(event, index, this, from);
}

function processImageTap(event, imageIndex, context, dataKey) {
    var path, data = context.data[dataKey];
    if (data && 0 != data.images.length) {
        var images = data.images;
        console.log(event.detail.width), console.log(images[imageIndex]);
        var dimensions = calculateImageDimensions(event.detail.width, event.detail.height, context, dataKey);
        console.log(dimensions);
        var imageIdx = images[imageIndex].index;
        event.detail.width, event.detail.height, images[imageIndex].attr.width && (images[imageIndex].attr.width, images[imageIndex].attr.height);
        var keyPath = "" + dataKey, shouldContinue = !0, hasError = !1, error = void 0;
        try {
            for (var step, iterator = imageIdx.split(".")[Symbol.iterator](); !(shouldContinue = (step = iterator.next()).done); shouldContinue = !0) keyPath += ".nodes[" + step.value + "]";
        } catch (err) {
            hasError = !0, error = err;
        } finally {
            try {
                !shouldContinue && iterator.return && iterator.return();
            } finally {
                if (hasError) throw error;
            }
        }
        var widthKey = keyPath + ".width", heightKey = keyPath + ".height";
        context.setData((defineProperty(path = {}, widthKey, dimensions.imageWidth), defineProperty(path, heightKey, dimensions.imageheight), path));
    }
}

function calculateImageDimensions(originalWidth, originalHeight, context, dataKey) {
    var result, newWidth = 0, newHeight = 0, dimensions = {}, padding = context.data[dataKey].view.imagePadding;
    return (result = windowWidth - 2 * padding) < originalWidth ? (newHeight = (newWidth = result) * originalHeight / originalWidth, dimensions.imageWidth = newWidth, dimensions.imageheight = newHeight) : (dimensions.imageWidth = originalWidth, 
    dimensions.imageheight = originalHeight), dimensions;
}

var showdownModule = processModuleExport(require("./showdown.js")), html2JsonModule = processModuleExport(require("./html2json.js")), windowWidth = 0, windowHeight = 0;

wx.getSystemInfo({
    success: function(systemInfo) {
        windowWidth = systemInfo.windowWidth, windowHeight = systemInfo.windowHeight;
    }
}), module.exports = {
    wxParse: function(dataKey, contentType, content, context, imagePadding) {
        var parsedDataKey = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "wxParseData", parsedContentType = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "html", parsedContent = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : '<div class="color:red;">数据不能为空</div>', parsedContext = context, parsedImagePadding = imagePadding, parsedOptions = {};
        if ("html" == parsedContentType) parsedOptions = html2JsonModule.default.html2json(parsedContent, parsedDataKey); else if ("md" == parsedContentType || "markdown" == parsedContentType) {
            var markdownHtml = new showdownModule.default.Converter().makeHtml(parsedContent);
            parsedOptions = html2JsonModule.default.html2json(markdownHtml, parsedDataKey);
        }
        parsedOptions.view = {}, void (parsedOptions.view.imagePadding = 0) !== parsedImagePadding && (parsedOptions.view.imagePadding = parsedImagePadding);
        var setData = {};
        setData[parsedDataKey] = parsedOptions, parsedContext.setData(setData), parsedContext.wxParseImgTap = logMessage, parsedContext.wxParseImgLoad = handleImageTap;
    },
    wxParseTemArray: function(arrayName, dataKeyPrefix, arrayLength, context) {
        for (var resultArray = [], data = context.data, setData = null, index = 0; index < arrayLength; index++) {
            var nodes = data[dataKeyPrefix + index].nodes;
            resultArray.push(nodes);
        }
        arrayName = arrayName || "wxParseTemArray", (setData = JSON.parse('{"' + arrayName + '":""}'))[arrayName] = resultArray, context.setData(setData);
    },
    emojisInit: function(emojisDataKey, emojisPath, context) {
        var dataKey = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", path = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "/wxParse/emojis/", parsedContext = context;
        html2JsonModule.default.emojisInit(dataKey, path, parsedContext);
    }
};